﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestConsole
{
    public interface IFormControlInfo
    {

    }

    /// <summary>
    /// 组控件类型
    /// </summary>
    public enum GType
    {
        none,
        radio = 5,
        checkbox = 6,
    }

    public class FormControlBase
    {
        /// <summary>
        /// 当前组件是软件自动生成，用来解决 一些显示界面问题的
        /// 比如对于checkbox和radio，目前解析器只能识别input控件
        /// 但是控件前面需要一个label，就需要由软件自动生成
        /// </summary>
        public GType GType { get; set; }
        public string Label { get; set; }
        public string Name { get; set; }
        public string Id { get; set; }
        public string Class { get; set; }

        public override string ToString()
        {
            return $"{GetType().Name},label={Label},name={Name},id={Id},class={Class},GType={GType}";
        }

        /// <summary>
        /// 对于radio和checkbox，会使用到这个属性
        /// 父对象相当于一个group对象
        /// 包含多个inpute对象
        /// </summary>
        public List<FormControlBase> Children { get; set; } = new List<FormControlBase>();
    }
    public class InputInfo : FormControlBase
    {
        public InputType InputType { get; set; }

        /// <summary>
        /// 对于checkbox类型，值的格式为  1,2,3 拼接字符串
        /// </summary>
        public string StringValue { get; set; } = string.Empty;
        public DateTime DateValue { get; set; }

        public override string ToString()
        {
            return $"{base.ToString()},type={InputType}";
        }
    }

    public class TextareaInfo : FormControlBase
    {
        public string StringValue { get; set; } = string.Empty;
    }

    public class SelectInfo : FormControlBase
    {
        public string StringValue { get; set; } = string.Empty;

        /// <summary>
        /// 多选下拉框的值
        /// </summary>
        public List<string> MultiStringValue { get; set; } = new List<string>();
        /// <summary>
        /// 是否允许多选
        /// </summary>
        public bool IsMultiple { get; set; }
        public List<OptionInfo> Options { get; set; } = new List<OptionInfo>();

        public override string ToString()
        {
            return $"{base.ToString()},IsMultiple={IsMultiple},options={string.Join(",", Options.Select(o => o.Value))}";
        }
    }

    public class OptionInfo
    {
        public string Value { get; set; } = string.Empty;
        public string Text { get; set; } = string.Empty;
    }

    [Flags]
    public enum InputType
    {
        none,
        date,
        text,
        password,
        radio = 5,
        checkbox = 6,
    }
}
